﻿// Decompiled with JetBrains decompiler
// Type: MCM.LightInject.AssemblyLoader
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;

#nullable disable
namespace MCM.LightInject
{
  [ExcludeFromCodeCoverage]
  internal class AssemblyLoader : IAssemblyLoader
  {
    public IEnumerable<Assembly> Load(string searchPattern)
    {
      string directory = Path.GetDirectoryName(new Uri(this.GetAssemblyCodeBasePath()).LocalPath);
      string[] searchPatterns = searchPattern.Split('|');
      foreach (string file in ((IEnumerable<string>) searchPatterns).SelectMany<string, string>((Func<string, IEnumerable<string>>) (sp => (IEnumerable<string>) Directory.GetFiles(directory, sp))).Where<string>(new Func<string, bool>(this.CanLoad)))
        yield return this.LoadAssembly(file);
    }

    protected virtual bool CanLoad(string fileName) => true;

    protected virtual Assembly LoadAssembly(string filename) => Assembly.LoadFrom(filename);

    protected virtual string GetAssemblyCodeBasePath()
    {
      return typeof (ServiceContainer).Assembly.Location;
    }
  }
}
